/**
 * 订单管理 交易订单
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>待支付订单</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <!-- <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.machineNo" placeholder="输入订单号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input size="small" v-model="formInline.orderNo" placeholder="输入订单号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input size="small" v-model="formInline.transId" placeholder="输入分类名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-select size="small" v-model="formInline.payType" placeholder="请选择">
          <el-option v-for="type in payType" :label="type.key" :value="type.value" :key="type.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select size="small" v-model="formInline.orderStatus" placeholder="请选择">
          <el-option v-for="type in payway" :label="type.key" :value="type.value" :key="type.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item> -->
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="index" width="25">
      </el-table-column>
      <el-table-column sortable prop="order_id" label="订单号" width="230" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="order_createusername" label="用户名" width="110" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="order_itemtypename" label="分类名" width="140" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="order_yuguname" label="重量" width="90" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="order_yuyuetime" label="预约时间" width="160" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable label="地址" width="300" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>
            {{formatAddess(scope.row)}}
          </div>
        </template>
      </el-table-column>
      <el-table-column sortable prop="order_area.telNumber" label="电话" width="110" show-overflow-tooltip>
      </el-table-column>
       <el-table-column sortable prop="order_statusname" label="状态" width="85" show-overflow-tooltip>
      </el-table-column> 
      <el-table-column  label="收款码" width="100" show-overflow-tooltip>
        <template slot-scope="scope">
            <el-popover placement="top-start" title="" trigger="hover">
              <img :src="'data:image/png;base64,'+scope.row.img_zhifu" style="width: 300px;height: 300px" alt="Base64 Image">
              <img slot="reference" :src="'data:image/png;base64,'+scope.row.img_zhifu" style="width: 60px;height: 60px" alt="Base64 Image">
            </el-popover>
        </template>
      </el-table-column>
      <el-table-column sortable prop="qishou_username" label="回收员" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="60">
        <template slot-scope="scope">
          <el-button size="mini" @click="orderDetail(scope.$index, scope.row)">详情</el-button>
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">已支付</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination> 
    <!--订单详情界面开始 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" :data="PayorderDetail.Detail" width="40%" @click="closeDialog('editForm')">
      <!-- <el-form ref="editForm" label-width="350px" class="detailform">
          <el-form-item v-for="(item, index) in PayorderDetail.Detail" :label="item.picker" :key="index" class="detailformitem">
            重量：<span v-text="item.value"></span>Kg，
            金额：<span v-text="item.price"></span>元            
          </el-form-item>
      </el-form> -->
      <el-table size="small" :data="PayorderDetail.Detail" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
        <el-table-column align="center"  type="index" width="25">
        </el-table-column>
        <el-table-column sortable prop="picker" label="回收类型" width="400" show-overflow-tooltip>
        </el-table-column>
        <el-table-column sortable prop="value" label="重量(kg)" width="150" show-overflow-tooltip>
        </el-table-column>
        <el-table-column sortable prop="totalPrice" label="金额(元)" width="150" show-overflow-tooltip>
        </el-table-column>
      </el-table>
      <div style="text-align: right; font-size: 20px; font-weight: bold; padding-top: 10px;">
        总金额：<span v-text="PayorderDetail.totalPrice" class="price"></span>元
      </div>      
      <div slot="footer" class="dialog-footer" style="text-align: center; font-weight: bold;">
        <el-button size="small" @click="closeDialog('editForm')">确定</el-button>
      </div>
    </el-dialog>
   <!--订单详情界面结束 -->
  </div>
</template>

<script>
import { OrderList, ConfigSave, waitPayList, finishOrderstatus } from '../../api/payMG'
import { roleList } from '../../api/userMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '订单详情',
      payType:[],
      payway: [
        { key: '请选择', value: 0 },
        { key: '初始化', value: 1 },
        { key: '已支付', value: 2 },
        { key: '出货成功', value: 3 },
        { key: '出货失败', value: 4 },
        { key: '订单超时', value: 5 },
        { key: '退款初始化', value: 11 },
        { key: '退款进行中', value: 12 },
        { key: '退款成功', value: 13 },
        { key: '退款失败', value: 14 },
        { key: '订单处理中', value: 10 }
      ],
      editForm: {
        id: '',
        name: '',
        payType: 1,
        partner: '',
        subMchId: '',
        appid: '',
        notifyUrl: '',
        signType: '',
        partnerKey: '',
        sellerUserId: '',
        certPath: '',
        certPassword: '',
        rsaKey: '',
      },
      // 支付完成,存储当前订单
      finishOrder:{
        orderid:'',   ////订单ID
      },
      formInline: {
        page: 1,
        limit: 10,
        machineNo: '',
        orderNo: '',
        transId: '',
        payType: '选择回收员',
        orderStatus: 0,
      },
      listData: [], //未分配订单数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      },
      PayorderDetail:{
        Detail:[],   ///订单详情项
        totalPrice:0  ////订单总金额
      }

    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 拼接地址多个字段
    formatAddess(item){      
      return `${item.order_area.provinceName}${item.order_area.cityName}${item.order_area.countyName}${item.order_area.detailInfo}`
    },
    // 转换状态
    formatstatus(item){
       let status = `${item.order_status}`
       return status==1?'待分配':''
    },
    // 获取订单数据
    getdata(parameter) {
      // 加载数据开始
      this.loading = true
      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
      waitPayList(parameter)
        .then(res => {
          this.loading = false
          if (res.data.orderlist.length == 0) {
            this.$message({
              type: 'info',
              message: '没有待支付的订单'
            })
            // 若没有待支付订单，就给个空值
            this.listData = res.data.orderlist
            // // 刷新当前页面
            // return this.$router.og(0)
            
          } else {
            // 有数据就赋值给数组
            console.log('获取待支付订单数据：',res)
            this.listData = res.data.orderlist
            // 分页赋值
            this.pageparm.currentPage = this.formInline.page
            this.pageparm.pageSize = this.formInline.limit
            this.pageparm.total = res.data.length
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    //支付完成后，点击完成订单
    handleEdit: function(index, row) {  
      //保存订单号 
      this.editForm = row    
      this.finishOrder.orderid =  this.editForm.order_id
      this.submitForm()
    },
    // 点击查询订单详情
    orderDetail: function(index, row){
      console.log('orderDetail',row.order_iteminfo.classifyDetail,row.order_iteminfo.totalPrice)
      this.PayorderDetail.Detail = row.order_iteminfo.classifyDetail
      this.PayorderDetail.totalPrice = row.order_iteminfo.totalPrice
      this.editFormVisible = true
    },
    // 支付完成后点击已支持，并修改订单状态1-待接单，2-待收取，3-已完成，4-已取消，5-待付款
    submitForm(editData) {
      // 调用保存接口前先保存订单号、骑手ID          
      // console.log('editRecycler:',this.finishOrder)
      finishOrderstatus(this.finishOrder)
        .then(res => {
          this.editFormVisible = false
          this.loading = false
          if (res.data.orderinfo != '') {
            this.getdata(this.formInline)
            this.$message({
              type: 'success',
              message: '订单完成！'
            })
          } else {
            this.$message({
              type: 'info',
              message: res.msg
            })
          }
        })
        .catch(err => {
          this.editFormVisible = false
          this.loading = false
          this.$message.error('保存失败，请稍后再试！')
        })
    },
    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
/* .detailform{
  border: 1px solid #ccc;
  padding: 10px;
} */
.detailformitem{
  border: 1px solid #ccc;
  padding: 5px;
  text-align: center;

}
.spandetail{
  border: 1px solid #ccc;
  margin-right: 20px;
  height: 200px;
}
</style>

 
 

 